package com.exam.utils;

import com.exam.enums.UserStatusEnum;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by v
 * Date:2019/1/7
 * Time:12:38
 */
public class UserUtils {

    public static Map<String, String> checkUserForm(Map<String, Object> registerInfo, HttpServletRequest request) {

        Map<String, String> map = new HashMap<>();
        //判断两次输入的密码
        if (!registerInfo.get("password").equals(registerInfo.get("verifyPassword"))) {
            map.put("code", String.valueOf(UserStatusEnum.USER_VERIFYPASSWORD_ERROR.getCode()));
            map.put("message", UserStatusEnum.USER_VERIFYPASSWORD_ERROR.getMessage());
            return map;
        }
        System.out.println(request.getSession().getAttribute(registerInfo.get("userCaptchaKey").toString()));
        //判断验证码
        if (!request.getSession().getAttribute(registerInfo.get("userCaptchaKey").toString()).toString().equalsIgnoreCase(registerInfo.get("userCaptcha").toString())) {
            request.getSession().removeAttribute(registerInfo.get("userCaptchaKey").toString());
            map.put("code", String.valueOf(UserStatusEnum.USER_CAPTCHA_ERROR.getCode()));
            map.put("message", UserStatusEnum.USER_CAPTCHA_ERROR.getMessage());
            return map;
        }
        String MessageCaptchaKey = registerInfo.get("userPhone").toString() + "captcha";
        /**
        //判断短信验证码
        if (!request.getSession().getAttribute(MessageCaptchaKey).equals(registerInfo.get("userMessage").toString())) {
            map.put("code", String.valueOf(UserStatusEnum.USER_MESSAGE_ERROR.getCode()));
            map.put("message", UserStatusEnum.USER_MESSAGE_ERROR.getMessage());
            return map;
        }
         */
        map.put("code", String.valueOf(UserStatusEnum.USER_SUCCESS.getCode()));
        map.put("message", UserStatusEnum.USER_SUCCESS.getMessage());
        return map;
    }
}
